package com.example.firstdemo

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class ButtonActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_button)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val btn = findViewById<View>(R.id.button2)
        btn.setOnClickListener {
            Toast.makeText(this, "点击按钮2", Toast.LENGTH_SHORT).show()
        }
        val btn3 = findViewById<View>(R.id.button3)
        btn3.setOnClickListener(this) // 设置监听器为当前 Activity
        val btn4 = findViewById<View>(R.id.button4)
        btn4.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        // 需要通过 view.id 来区分不同的按钮。
        when (v?.id) {
            R.id.button3 -> Toast.makeText(this, "点击按钮3", Toast.LENGTH_SHORT).show()
        }
        when (v?.id) {
            R.id.button4 -> Toast.makeText(this, "点击按钮4", Toast.LENGTH_SHORT).show()
        }
    }

    fun btn1(view: View) {
        Toast.makeText(this, "点击按钮1", Toast.LENGTH_SHORT).show()
    }

    // 1. 获取按钮


}